//
//  GYMineOrderEditCell.m
//  GYDemo
//
//  Created by mac on 2018/4/12.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYMineOrderEditCell.h"
#import "Head.h"

@interface GYMineOrderEditCell()<UITextFieldDelegate>
@property (nonatomic,strong) UILabel *priceUnitLB;
@property (nonatomic,strong) UILabel *countUnitLB;
@end
@implementation GYMineOrderEditCell
#pragma mark - getter and setter
-(UILabel *)priceUnitLB
{
    if (!_priceUnitLB) {
        _priceUnitLB = [[UILabel alloc]init];
        _priceUnitLB.backgroundColor = Main_Color_White;
        _priceUnitLB.x = self.priceTF.right;
        _priceUnitLB.y = self.priceTF.y;
        _priceUnitLB.width = WFCGFloatX(17);
        _priceUnitLB.height = WFCGFloatY(25);
        _priceUnitLB.textColor = Main_Color_Gray;
        _priceUnitLB.font = SYSTEMFONT(12);
        _priceUnitLB.text = @"元";
    }
    return _priceUnitLB;
}

-(UILabel *)countUnitLB
{
    if (!_countUnitLB) {
        _countUnitLB = [[UILabel alloc]init];
        _countUnitLB.backgroundColor = Main_Color_White;
        _countUnitLB.x = self.countTF.right;
        _countUnitLB.y = self.countTF.y;
        _countUnitLB.width = WFCGFloatX(17);
        _countUnitLB.height = WFCGFloatY(25);
        _countUnitLB.textColor = Main_Color_Gray;
        _countUnitLB.font = SYSTEMFONT(12);
    }
    return _countUnitLB;
}

-(void)setOrderListModel:(GYMineOrderInfoListModel *)orderListModel
{
    _orderListModel = [GYMineOrderInfoDetailGoodsModel yy_modelWithJSON:[orderListModel yy_modelToJSONData]];
    self.nameLB.text = _orderListModel.name;
    self.typeLB.text = [NSString stringWithFormat:@" %@ ",_orderListModel.protypename];
    NSString *picurl = [NSString stringWithFormat:@"%@%@",_orderListModel.picurl,kProductImgThumbnailSuffix];
    [self.imageIV sd_setImageWithURL:[NSURL URLWithString:picurl] placeholderImage:[UIImage imageNamed:@"default_goods"]];
    
    NSString *unit = _orderListModel.unit;
    _countUnitLB.text = unit;
//    NSString *counts = [NSString stringWithFormat:@"%@",unit];
//    self.countLB.text = counts;
//    NSString *priceUnit = [NSString stringWithFormat:@"元/%@",unit];
//    self.priceLB.text = priceUnit;
}
#pragma mark - method
+(CGFloat)finalHeight
{
    return WFCGFloatY(78+10);
}
#pragma mark - life
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = RGBACOLOR(247, 247, 247, 0.5);
        
        [self.contentView addSubview:self.priceTF];
        self.priceTF.backgroundColor = Main_Color_White;
        self.priceTF.textColor = Main_Color_Black;
        self.priceTF.frame = WFCGRectMake(299, 13, 70 - 7 - 5 - 17, 25);
        self.priceTF.textAlignment = NSTextAlignmentCenter;
        self.priceTF.font = SYSTEMFONT(12);
        [self.contentView addSubview:self.priceUnitLB];
        
        self.countTF.frame = WFCGRectMake(299, 48, 70 - 7 - 5 - 17, 25);
        self.countTF.backgroundColor = Main_Color_White;
        self.countTF.textColor = Main_Color_Black;
        self.countTF.font = SYSTEMFONT(12);
        self.countTF.enabled = YES;
        self.countTF.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.countUnitLB];
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.typeLB.x = self.nameLB.right + WFCGFloatX(5);
    self.typeLB.centerY = self.nameLB.centerY;
    
    self.priceTF.text = [NSString stringWithFormat:@"%ld",_orderListModel.price];
    self.countTF.text = [NSString stringWithFormat:@"%ld",_orderListModel.count];
}
#pragma mark - delegate
#pragma mark - text field delegate
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField.text && textField.text.integerValue > 0) {
        if (textField == self.priceTF) {
            if (self.callback) {
                self.callback(textField.text, 1);
            }
        }else{
            if (self.callback) {
                self.callback(textField.text, 0);
            }
        }
    }
}
@end
